package com.zhulanhua.blogs.Utils;

import com.zhulanhua.blogs.exception.SystemException;

import java.io.File;

public class FileUtils {
    public static void file(String path){
        File file = new File(path);
        //如果文件夹不存在则创建
        if (!file.exists() && !file.isDirectory()) {
            if (!file.mkdir()) throw new SystemException(Code.SYSTEM_ERR, "文件夹创建失败");
        }
    }

    public static boolean deleteFile(String path){
        return new File(path).delete();
    }

    public static void files(String path){
        FileUtils.files(path,null);
    }

    public static void files(String path, String[] files){
        String[] split = path.replace("\\","/").split("/");
        String str = "";
        for (int i = 0;i < split.length;i++){
            try {
                str += split[i] + (i == split.length - 1 ? "" : "\\");
                FileUtils.file(str);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if (files != null && files.length > 0){
            for (int i = 0;i < files.length;i++){
                FileUtils.file(str + files[i]);
            }
        }
    }
}
